package com.macro.mall.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.CmsSubjectMapper;
import com.macro.mall.domain.CmsSubject;
import com.macro.mall.service.CmsSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品专题管理Service实现类
 * Created by macro on 2018/6/1.
 */
@Service
public class CmsSubjectServiceImpl extends ServiceImpl<CmsSubjectMapper, CmsSubject> implements CmsSubjectService {

    @Override
    public List<CmsSubject> listAll() {
        List<CmsSubject> result = lambdaQuery()
                .select(CmsSubject::getId, CmsSubject::getCategoryId, CmsSubject::getTitle, CmsSubject::getPic, CmsSubject::getProductCount,
                        CmsSubject::getRecommendStatus, CmsSubject::getCreateTime, CmsSubject::getCollectCount, CmsSubject::getReadCount,
                        CmsSubject::getCommentCount, CmsSubject::getAlbumPics, CmsSubject::getDescription, CmsSubject::getShowStatus,
                        CmsSubject::getForwardCount, CmsSubject::getCategoryName)
                .list();
        /*
            id, category_id, title, pic, product_count, recommend_status, create_time, collect_count,
    read_count, comment_count, album_pics, description, show_status, forward_count, category_name
         */
        return result;
    }

    @Override
    public List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CmsSubject> result = lambdaQuery()
                .select(CmsSubject::getId, CmsSubject::getCategoryId, CmsSubject::getTitle, CmsSubject::getPic, CmsSubject::getProductCount,
                        CmsSubject::getRecommendStatus, CmsSubject::getCreateTime, CmsSubject::getCollectCount, CmsSubject::getReadCount,
                        CmsSubject::getCommentCount, CmsSubject::getAlbumPics, CmsSubject::getDescription, CmsSubject::getShowStatus,
                        CmsSubject::getForwardCount, CmsSubject::getCategoryName)
                .like(!StrUtil.isEmpty(keyword), CmsSubject::getTitle, "%" + keyword + "%")
                .list();
        return result;
    }
}
